from flask import session, redirect, jsonify

sessionName = 'username'


# 登录验证
def logincheck(func):
    def wrapper(*args, **kwargs):
        if not session.get(sessionName):
            return redirect('/account/login')
        return func(*args, **kwargs)

    return wrapper


# 登录验证，返回json
def logincheckjson(func):
    def wrapper(*args, **kwargs):
        if not session.get(sessionName):
            return jsonify({'code': 'login_timeout', 'msg': '登录超时，请重新登录'})
        return func(*args, **kwargs)

    return wrapper
